import { defHttp } from "/@/utils/http/axios"
import { Modal } from "ant-design-vue"
import { RequestHeaderEnum } from "/@/enums/httpEnum"

enum Api {
  list = "/msg-push-service/msgHistory/page",
  get = "/msg-push-service/msgHistory/get",
  delete = "/msg-push-service/msgHistory/delete",
  batchDelete = "/msg-push-service/msgHistory/batchDelete",
  rePush = "/msg-push-service/msgHistory/rePush",
  importExcel = "/msg-push-service/msgHistory/importExcel",
}

/**
 * 查询列表
 * @param params
 */
export const listMsgPush = (params) => {
  const headers = {}
  headers[RequestHeaderEnum.TENANT_ID] = params.tenantId
  return defHttp.get({ url: Api.list, params, headers })
}

/**
 * 查询详情
 * @param params
 */
export const getMsgHistory = (params) => {
  const headers = {}
  headers[RequestHeaderEnum.TENANT_ID] = params.tenantId
  return defHttp.get({ url: Api.get, params, headers })
}

/**
 * 重新推送
 * @param params
 */
export const rePush = (params) => {
  return defHttp.post({ url: `${Api.rePush}?id=${params.id}` })
}

/**
 * 单条删除
 * @param params
 */
export const deleteMsgPush = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.delete, data: params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess()
  })
}

/**
 * 批量删除
 * @param params
 */
export const batchDeleteMsgPush = (params, handleSuccess) => {
  Modal.confirm({
    title: "确认删除",
    content: "是否删除选中数据",
    okText: "确认",
    cancelText: "取消",
    onOk: () => {
      return defHttp.delete({ url: Api.batchDelete, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess()
      })
    },
  })
}
